<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    /**
     *
     * Khai bao cac table
     * @author Nguyen Manh Hung
     *        
     */
    protected function _initDefineTable() {
        $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/table.ini');
        foreach ($config->TABLE_DATABASE as $k => $value) {
            defined($k) ||
                    define($k, TABLE_PREFIX . trim($value));
        }
    }

    /**
     * Khai bao cac hang so
     * @author Nguyen Manh Hung
     */
    protected function _initDefindConstand() {
        defined('NUM_PER_PAGE') ||
                define('NUM_PER_PAGE', 50);
    }

    public function _initLoadHelper() {
        Zend_Controller_Action_HelperBroker::addPath(
                APPLICATION_PATH . '/modules/admin/views/helpers');
        Zend_Controller_Action_HelperBroker::addPath(
                APPLICATION_PATH . '/modules/front/views/helpers');
        Zend_Controller_Action_HelperBroker::addPath(
                APPLICATION_PATH . '/modules/user/views/helpers');
    }

    protected function _initLoadRouter() {
        $config = new Zend_Config_Ini(CONFIG_PATH . '/routers.ini', 'setup-router');
        $objRouter = new Zend_Controller_Router_Rewrite ();
        // new Zend_Controller_Router_Route_Regex()
        $router = $objRouter->addConfig($config, 'routers');
        $front = Zend_Controller_Front::getInstance();
        $front->setRouter($router);
    }

    protected function _initMail() {
        $tr = new Zend_Mail_Transport_Smtp('smtp.gmail.com', array(
            'auth' => 'login',
            'username' => 'nobitamanhhung@gmail.com',
            'password' => 'Hb14122006',
            'ssl' => 'ssl',
            'port' => 465
                ));

        Zend_Mail::setDefaultTransport($tr);
    }

    protected function _initCache() {
        $frontendOptions = array(
            'lifetime' => 2 * 24 * 60 * 60,
            'automatic_serialization' => true
        );
        $backendOptions = array(
            'cache_dir' => './tmp/'
        );
        $cache = Zend_Cache::factory('Core', 'File', $frontendOptions, $backendOptions);
        Zend_Registry::set('cache', $cache);
    }

}

